Author: Nicolas Legrand nicolas.legrand@cfin.au.dk
import os
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
from systole.detection import oxi_peaks
from systole.plotly import plot_subspaces, plot_raw
import plotly.io as pio
pio.renderers.default='notebook'
sns.set_context('talk')
Import data
path = 'C:/Users/au646069/ECG/1_VPN_aux/'
subject = 'sub_0019'
# Parameters
subject = "sub_0024"
path = "C:/Users/au646069/ECG/1_VPN_aux/"
resultsFiles = os.listdir(os.path.join(path, subject, 'HBC'))
# Logs dataframe
df = pd.read_csv(os.path.join(path, subject, 'HBC', [file for file in resultsFiles if file.endswith('final.txt')][0]))
df
| nTrial | Reported | Condition | Duration | Confidence | ConfidenceRT | |
|---|---|---|---|---|---|---|
| 0 | 0 | 34 | Count | 35 | 5 | 4.162 |
| 1 | 1 | 38 | Count | 40 | 3 | 2.439 |
| 2 | 2 | 31 | Count | 30 | 4 | 1.454 |
| 3 | 3 | 45 | Count | 45 | 4 | 3.197 |
| 4 | 4 | 36 | Count | 50 | 2 | 3.146 |
| 5 | 5 | 21 | Count | 25 | 5 | 1.376 |
# PPG signal
ppg = {}
for i in range(6):
ppg[str(i)] = np.load(os.path.join(path, subject, 'HBC', f'{subject[4:]}_{i}.npy'))
signal, peaks = oxi_peaks(ppg['0'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[0]} ; Detected : {np.sum(peaks)}')
Reported: 34 ; Detected : 48
signal, peaks = oxi_peaks(ppg['1'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[1]} ; Detected : {np.sum(peaks)}')
Reported: 38 ; Detected : 51
signal, peaks = oxi_peaks(ppg['2'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[2]} ; Detected : {np.sum(peaks)}')
Reported: 31 ; Detected : 42
signal, peaks = oxi_peaks(ppg['3'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[3]} ; Detected : {np.sum(peaks)}')
Reported: 45 ; Detected : 64
signal, peaks = oxi_peaks(ppg['4'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[4]} ; Detected : {np.sum(peaks)}')
Reported: 36 ; Detected : 72
signal, peaks = oxi_peaks(ppg['5'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[5]} ; Detected : {np.sum(peaks)}')
Reported: 21 ; Detected : 40